package com.it.you.base.designmode.factory;

/**
 * 简单工厂模式：一个工厂类 XxxFactory，里面有一个静态方法，根据我们不同的参数，返回不同的派生自同一个父类（或实现同一接口）的实例对象
 *
 * 工厂模式：多个工厂（可能都是某个工厂的子类），第一步选择好具体的工厂后，后续使用同简单工厂模式
 *
 * @Author : YouHui
 * @create 2023/4/12 11:55
 */
public class SimpleFactory {

    public static Food getFood(String name) {
        Food food = null;
        if (name.equals("lanzhou")) {
            food = new LanZhouNoodle(name);
            food.printName();
        } else if (name.equals("biangbiang")) {
            food = new BiangBiangNoodle(name);
            food.printName();
        }
        return food;
    }

    public static void main(String[] args) {
        getFood("biangbiang");
    }

}

interface Food {

    void printName();

}

class LanZhouNoodle implements Food {

    private String name;

    public LanZhouNoodle(String name) {
        this.name = name;
    }

    @Override
    public void printName() {
        System.out.println(name);
    }
}

class BiangBiangNoodle implements Food {

    private String name;

    public BiangBiangNoodle(String name) {
        this.name = name;
    }

    @Override
    public void printName() {
        System.out.println(name);
    }
}


